<?php
require_once '../setting/setting.php';
class sqlclass {
		var $result;
		var $numRows;
	
        function connect($dbhost, $dbuser, $dbpw, $dbname) {
                        if(!@mysql_pconnect($dbhost, $dbuser, $dbpw)) {
                                //$this->halt('Can not connect to MySQL server');
                        }
                        mysql_select_db($dbname);
        }
        function select_db($dbname) {
                return mysql_select_db($dbname);
        }

        function fetch_array($query, $result_type = MYSQL_ASSOC) {
                $query = mysql_fetch_array($query, $result_type);
                return $query;
        }

        function query($sql, $silence = 1) {

                $query = mysql_query($sql);
            	if(!$query && !$silence)
        	{
                       $this->halt('MySQL Query Error', $sql);
                }
                return $query;
        }

        function unbuffered_query($sql, $silence = 0) {
                $func_unbuffered_query = @function_exists('mysql_unbuffered_query') ? 'mysql_unbuffered_query' : 'mysql_query';
                $query = $func_unbuffered_query($sql);
                if(!$query && !$silence) {
                        $this->halt('MySQL unbuffered Query Error', $sql);
                }
                return $query;
        }
        function get_one($sql){
                if(function_exists('mysql_unbuffered_query')){
                        $query = mysql_unbuffered_query($sql);
                }else{
                        $query = mysql_query($sql);
                }
                if (!$query)  $this->halt('Query Error: ' . $sql);

                $rs =& mysql_fetch_array($query, MYSQL_ASSOC);
                mysql_free_result($query);
                return $rs;
        }

        function affected_rows() {
                return mysql_affected_rows();
        }

        function error() {
                return mysql_error();
        }

        function errno() {
                return mysql_errno();
        }

        function result($query, $row) {
                $query = @mysql_result($query, $row);
                return $query;
        }

        function num_rows($query) {
                $query = mysql_num_rows($query);
                return $query;
        }

        function num_fields($query) {
                return mysql_num_fields($query);
        }

        function free_result($query) {
                return mysql_free_result($query);
        }

        function insert_id() {
                $id = mysql_insert_id();
                return $id;
        }

        function fetch_row($query) {
                $query = mysql_fetch_row($query);
                return $query;
        }

        function close() {
                return mysql_close();
        }
        function halt($message = '', $sql = '') {
                        echo $message;
			//echo "<META HTTP-EQUIV=REFRESH CONTENT='0;URL=./error.html'>";
                     }
                     
                     
	/**************************/
	public function ivSelect($columns, $table, $condition = 1) {
		$query = "SELECT $columns FROM $table WHERE $condition";
		$this->result = @mysql_query($query);
		$this->numRows = @mysql_num_rows($this->result);
		return true;
	}
	
	public function ivInsert($columns, $table, $values) {
		$query = "INSERT INTO $table ($columns) VALUES ($values)";
		$this->result = @mysql_query($query, $this->dbLink);
		return true;
	}
	
	public function ivUpdate($table, $settings, $condition) {
		$query = "UPDATE $table SET $settings WHERE $condition";
		$this->result = @mysql_query($query); 
		$this->numRows=@mysql_affected_rows($this->result);
		return true;
	}
	
	public function ivDelete($table, $condition) {
		$query = "DELETE FROM $table WHERE $condition";
		$this->result = @mysql_query($query); 
		$this->numRows = @mysql_affected_rows($this->result);
		return true;
	}
}
$db = new sqlclass;
$db->connect($dbhost, $dbuser, $dbpw,$dbname);
unset($dbhost, $dbuser, $dbpw, $dbname);
?>
